<template>
    <el-drawer title="图表信息配置" v-model="visible" size="40%" :before-close="handleClose" destroy-on-close>
        <main class="main">
            <div class="main-top">
                <Chart :config="chartConifg" />
            </div>
            <div class="main-mid">
                <el-form label-position="right" label-width="80px" :model="form">
                    <el-form-item label="图表名称">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item>
                    <el-form-item label="刷新频率">
                        <el-input-number v-model="form.rest"></el-input-number>
                        (单位：分)
                    </el-form-item>
                    <el-form-item label="刷新形式">
                        <el-radio v-model="form.radio" label="zhuijia">追加</el-radio>
                        <el-radio v-model="form.radio" label="fugai">覆盖</el-radio>
                    </el-form-item>
                    <el-form-item label="数据URL">
                        <el-input v-model="form.url"></el-input>
                    </el-form-item>
                </el-form>
            </div>
            <div class="main-bottom">
                <el-button type="primary" @click="onSubmit">立即创建</el-button>
                <el-button @click="handleClose">取消</el-button>
            </div>
        </main>
    </el-drawer>
</template>

<script>
import Chart from '../Echart/chart';

export default {
    name: 'Drawer',
    emits: ['drawerClose'],
    components: {
        Chart,
    },
    props: {
        drawerVisible: Boolean,
        chartConifg: Object,
        formData: Object,
    },
    computed: {
        visible() {
            return this.drawerVisible;
        },
    },
    data() {
        return {
            form: {
                name: '',
                rest: 0,
                radio: '',
                url: '',
            },
        };
    },
    mounted() {
        Object.assign(this.form, this.formData);
    },
    methods: {
        handleClose() {
            this.$confirm('确认关闭？')
                .then(() => {
                    this.$emit('drawerClose');
                    // done();
                })
                .catch(() => {});
        },
        onSubmit() {
            this.$emit('drawerClose', this.form);
        },
    },
};
</script>

<style lang="scss" scoped>
.main {
    width: 100%;
    height: 100%;
    overflow: auto;
    padding: 10px;
    &-top {
        width: 70%;
        height: 400px;
        margin: 0 auto;
    }
}
</style>
